package com.freesky.biz.activity.service.impl;

import com.freesky.biz.activity.domain.TAssignCoupon;
import com.freesky.biz.activity.domain.TContract;
import com.freesky.biz.activity.domain.TProject;
import com.freesky.biz.activity.domain.TProjectRelatedLog;
import com.freesky.biz.activity.mapper.ContractMapper;
import com.freesky.biz.activity.mapper.ProjectMapper;
import com.freesky.biz.activity.service.IContractService;
import com.freesky.biz.activity.service.IProjectService;
import com.freesky.biz.utils.SeqUtil;
import com.freesky.common.constant.UserConstants;
import com.freesky.common.exception.base.BaseException;
import com.freesky.common.utils.SecurityUtils;
import com.freesky.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContractServiceImpl implements IContractService {

    @Autowired
    private ContractMapper contractMapper;

    @Override
    public TContract get(String id) {
        return contractMapper.get(id);
    }

    @Override
    public List<TContract> findList(TContract entity) {
        return contractMapper.findList(entity);
    }

    @Override
    public TContract selectSummaryData(TContract entity) {
        return contractMapper.selectSummaryData(entity);
    }

    @Override
    public boolean checkContractNameUnique(TContract entity) {
        String contractId = entity.getContractId();
        TContract info = contractMapper.selectContractByName(entity.getContractName());
        if (StringUtils.isNotNull(info) && !info.getContractId().equalsIgnoreCase(contractId)) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public boolean checkContractNoUnique(TContract entity) {
        String contractId = entity.getContractId();
        TContract info = contractMapper.selectContractByNo(entity.getContractNo());
        if (StringUtils.isNotNull(info) && !info.getContractId().equalsIgnoreCase(contractId)) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public int selectProjectCount(String contractId) {
        return contractMapper.selectProjectCount(contractId);
    }

    @Override
    public int insert(TContract entity) {
        return contractMapper.insert(entity);
    }

    @Override
    public int update(TContract entity) {
        return contractMapper.update(entity);
    }

    @Override
    public int deleteByIds(String[] ids) {
        return contractMapper.deleteByIds(ids);
    }


}
